package madixin.t690;

import java.util.List;

class Solution {
    private List<Employee> employees;

    public int getImportance(List<Employee> employees, int id) {
        this.employees = employees;
        Employee cur = findEmployee(id);
        if (cur == null) {
            return 0;
        }
        return getImportance(cur);
    }

    private int getImportance(Employee employee) {
        int importance = employee.importance;
        for (Integer subId : employee.subordinates) {
            importance += getImportance(findEmployee(subId));
        }
        return importance;
    }

    private Employee findEmployee(int id) {
        for (Employee employee : this.employees) {
            if (employee.id == id) {
                return employee;
            }
        }
        return null;
    }
}
